package protocol.role;

import java.io.ByteArrayOutputStream;
import java.io.UnsupportedEncodingException;

import protocol.BasicProtocol;
import protocol.Iprotocol;
import util.ProtocolUtils;
import config.SystemDefine;

public class Role_protocol extends BasicProtocol implements Iprotocol {
	
	private int		sex				= 0;
	
	private int		level			= 0;
	
	private String	names			= "";
	
	private int		user_id			= 0;
	
	private int		currentMapId	= 0;
	
	public Role_protocol() {
		Type = SystemDefine.getInstance().getROLE_ID();
	}
	
	public int getType() {
		return Type;
	}
	
	public void setType(int type) {
		this.Type = type;
	}
	
	public int getSex() {
		return sex;
	}
	
	public void setSex(int sex) {
		this.sex = sex;
	}
	
	public int getLevel() {
		return level;
	}
	
	public void setLevel(int level) {
		this.level = level;
	}
	
	public String getNames() {
		return names;
	}
	
	public void setNames(String names) {
		this.names = names;
	}
	
	public int getUser_id() {
		return user_id;
	}
	
	public void setUser_id(int user_id) {
		this.user_id = user_id;
	}
	
	public void setCurrentMapId_id(int _currentMapId) {
		currentMapId = _currentMapId;
	}
	
	@Override
	public byte[] write() {
		
		ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
		
		byte[] typeByteArr = ProtocolUtils.int2byteArray(Type);
		byte[] userIdArr = ProtocolUtils.int2byteArray(user_id);
		byte[] cureentMapIdArr = ProtocolUtils.int2byteArray(currentMapId);
		byte[] sexArr = ProtocolUtils.int2byteArray(sex);
		byte[] levelArr = ProtocolUtils.int2byteArray(level);
		String charset="UTF-8";
		byte[] nameArr = null;
		try {
			nameArr = names.getBytes(charset);
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		
		enCodeFormat(outputStream, typeByteArr);
		enCodeFormat(outputStream, userIdArr);
		enCodeFormat(outputStream, cureentMapIdArr);
		enCodeFormat(outputStream, sexArr);
		enCodeFormat(outputStream, levelArr);
		enCodeFormat(outputStream, nameArr);
		
		return outputStream.toByteArray();
	}
	
}
